﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace AlarmManagePlatform.Forms
{
    public partial class SetupForm : RelationsLMP.Control.Form.MetroDemoForms
    {
        public SetupForm()
        {
            InitializeComponent();

            InitControls();
        }

        private void InitControls()
        {
            InitComBoxImageVer();

            okReturnToolbar21.Event_OKClick += OkReturnToolbar21_Event_OKClick;
            okReturnToolbar21.Event_ReturnClick += OkReturnToolbar21_Event_ReturnClick;
        }

        private void OkReturnToolbar21_Event_OKClick(object sender, EventArgs e)
        {
            try
            {
                new DataAccess.tb_DictInfo().UpdateDictValue("imageRecognition","ver",cmbImageVer.SelectedValue.ToString());
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, "保存修改失败，错误信息：" + ex.ToString(), "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                this.DialogResult = DialogResult.OK;
            }
        }

        private void OkReturnToolbar21_Event_ReturnClick(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
        }

        private void InitComBoxImageVer()
        {
            List<Model.DB.tb_DictInfo> _DictInfoList;
            cmbImageVer.DropDownStyle = ComboBoxStyle.DropDownList;
            cmbImageVer.DisplayMember = "Description";
            cmbImageVer.ValueMember = "value";

            List<RelationsLMP.Model.ObjectInfo> _List = new List<RelationsLMP.Model.ObjectInfo>()
            {
                new RelationsLMP.Model.ObjectInfo()
                {
                    Description = "版本1",
                    value = "1"

                },
                new RelationsLMP.Model.ObjectInfo()
                {
                    Description = "版本2",
                    value = "2"

                },
            };

            cmbImageVer.DataSource = _List;
            try
            {
                _DictInfoList = new DataAccess.tb_DictInfo().GetDictInfoList("imageRecognition", "ver");

                if (_DictInfoList.Count <= 0)
                    cmbImageVer.SelectedValue = "2";

                else
                    cmbImageVer.SelectedValue = _DictInfoList[0].DictValue;
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, "初始化ComBoxImageVer异常，错误信息：" + ex.ToString(), "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

    }
}
